package com.hancher.gamelife2.main;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;

import com.hancher.common.androidutil.FastClickUtil;
import com.hancher.common.androidutil.LogUtil;
import com.hancher.common.androidutil.ToastUtil;
import com.hancher.common.base.BaseActivity;
import com.hancher.gamelife2.R;
import com.hancher.gamelife2.databinding.ActivityMainBinding;

public class MainActivity extends BaseActivity<ActivityMainBinding> {
    private NavController navController;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //必须要有的
        navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_main);
//        //标题绑定
//        AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
//                R.id.navigation_home, R.id.navigation_dashboard)
//                .build();
//        NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
//        //导航栏绑定
//        NavigationUI.setupWithNavController(binding.navView, navController);
    }

    @Override
    public void onBackPressed() {
//        super.onBackPressed();
        LogUtil.d("back " + navController.getCurrentDestination());
        if (navController.getCurrentDestination() != null && navController.getCurrentDestination().getId() == R.id.mainFragment) {
            if (FastClickUtil.isQuick()) {
                MainApplication.finish();
            } else {
                ToastUtil.show("再次点击返回，退出应用");
            }
        } else {
            navController.navigateUp();
        }

    }

    @Override
    protected void onResume() {
        super.onResume();


//        binding.tvHelloWord.setText("欢迎");
//
//        binding.tvHelloWord.setOnClickListener(v -> {
//            Map<String, String> map = new HashMap<>();
//            map.put("type", "shunfeng");
//            map.put("postid", "SF1514041837186");
//            NetInterface.service.test(map)
//                    .compose(AsyncUtils.getThreadTransformer())
//                    .subscribe(new DialogObserver<>(this) {
//
//                        @Override
//                        public void onNext(NetBean netBean) {
//                            binding.tvHelloWord.setText(GsonUtil.obj2JsonStr(netBean));
//                        }
//                    });
//        });

    }
}